class Mobile::Weixin::CarsController < Mobile::Weixin::WeixinController
    before_action :get_car

    def index             
        redirect_to action: :show,id: @car.id,format: :json
    end  

    def show
        @car = Car.find params[:id]
    end  

    def add
       @car.add_food params[:food_id]         
       redirect_to action: :show,id: @car.id,format: :json
    end   

    def clear 
        @car.clear_all
        redirect_to action: :show,id: @car.id,format: :json
    end  

    def remove
      @car.subtract_food params[:food_id] 
      redirect_to action: :show,id: @car.id,format: :json
    end    

    private
    def get_car
        @car = Car.find_or_create_by(user_id: @current_user.id,restaurant_id:@restaurant.id)
        if params[:table_no].present?
            @car.current_table_no = params[:table_no].to_i
            @car.save
        end 
    end    

end
